package com.uls.web.controller.ycl;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.uls.common.annotation.Log;
import com.uls.common.core.controller.BaseController;
import com.uls.common.core.domain.AjaxResult;
import com.uls.common.enums.BusinessType;
import com.uls.ycl.domain.RepairArea;
import com.uls.ycl.service.IRepairAreaService;
import com.uls.common.utils.poi.ExcelUtil;
import com.uls.common.core.page.TableDataInfo;

/**
 * 报修区域Controller
 * 
 * @author ycl
 * @date 2024-11-06
 */
@RestController
@RequestMapping("/ycl/area")
public class RepairAreaController extends BaseController
{
    @Autowired
    private IRepairAreaService repairAreaService;

    /**
     * 查询报修区域列表
     */
    @PreAuthorize("@ss.hasPermi('ycl:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(RepairArea repairArea)
    {
        startPage();
        List<RepairArea> list = repairAreaService.selectRepairAreaList(repairArea);
        return getDataTable(list);
    }

    /**
     * 导出报修区域列表
     */
    @PreAuthorize("@ss.hasPermi('ycl:area:export')")
    @Log(title = "报修区域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RepairArea repairArea)
    {
        List<RepairArea> list = repairAreaService.selectRepairAreaList(repairArea);
        ExcelUtil<RepairArea> util = new ExcelUtil<RepairArea>(RepairArea.class);
        util.exportExcel(response, list, "报修区域数据");
    }

    /**
     * 获取报修区域详细信息
     */
    @PreAuthorize("@ss.hasPermi('ycl:area:query')")
    @GetMapping(value = "/{areaId}")
    public AjaxResult getInfo(@PathVariable("areaId") Long areaId)
    {
        return success(repairAreaService.selectRepairAreaByAreaId(areaId));
    }

    /**
     * 新增报修区域
     */
    @PreAuthorize("@ss.hasPermi('ycl:area:add')")
    @Log(title = "报修区域", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RepairArea repairArea)
    {
        return toAjax(repairAreaService.insertRepairArea(repairArea));
    }

    /**
     * 修改报修区域
     */
    @PreAuthorize("@ss.hasPermi('ycl:area:edit')")
    @Log(title = "报修区域", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RepairArea repairArea)
    {
        return toAjax(repairAreaService.updateRepairArea(repairArea));
    }

    /**
     * 删除报修区域
     */
    @PreAuthorize("@ss.hasPermi('ycl:area:remove')")
    @Log(title = "报修区域", businessType = BusinessType.DELETE)
	@DeleteMapping("/{areaIds}")
    public AjaxResult remove(@PathVariable Long[] areaIds)
    {
        return toAjax(repairAreaService.deleteRepairAreaByAreaIds(areaIds));
    }


    /*获取所有区域信息*/
    @GetMapping("/getAllAreas")
    public AjaxResult getAllAreas()
    {
        List<RepairArea> list = repairAreaService.selectRepairAreaList(null);
        return success(list);
    }






}
